class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* guard = new ListNode;
        guard->next = head;
        ListNode* cur = guard->next;
        while (cur && cur->next)
        {
            while (cur->next && cur->val == cur->next->val)
            {
                ListNode* del = cur->next;
                cur->next = cur->next->next;
                delete del;
            }
            cur = cur->next;
        }
        head = guard->next;
        delete guard;
        return head;
    }
};